using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ResourceManager : MonoSingleton<ResourceManager>
{
    public override void Init()
    {
        base.Init();
    }
    public T LoadRes<T>(string path) where T : Object
    {
        T res = null;
        try
        {
            res = (T)Resources.Load(path);
        }
        catch (System.Exception e)
        {
            Debug.Log(e.Message);
        }
        return res;
    }
    public List<T> LoadAllRes<T>(string path) where T : Object
    {
        List<T> ResList = new List<T>();
        try
        {
            T[] materials = Resources.LoadAll<T>(path);
            ResList.AddRange(materials);
        }
        catch (System.Exception e)
        {
            Debug.Log(e.Message);
        }
        return ResList;
    }
    public T LoadComponentFromPrefab<T>(string path) where T : Component
    {
        GameObject prefab = LoadRes<GameObject>(path);
        if (prefab == null) return null;
        return prefab.GetComponent<T>() ?? prefab.GetComponentInChildren<T>(true);
    }
}
